package com.tsn.controller;

import com.tsn.service.LikeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/tsn")
public class LikeController {
    @Autowired
    LikeService likeService;

    @RequestMapping(path = {"/like"}, method = {RequestMethod.GET, RequestMethod.POST})
    public String like(@RequestParam("newsId") int newsId,@RequestParam("userId")Integer userId,@RequestParam("entityType")Integer entityType){
        //在likeKey对应的集合中加入当前用户的id
        long likeCount = likeService.like(userId,entityType, newsId);

        //资讯上更新点赞数
//        newsService.updateLikeCount(newsId, (int)likeCount);
        return String.valueOf(likeCount);
    }

    @RequestMapping(path = {"/dislike"}, method = {RequestMethod.POST, RequestMethod.GET})
    public String disLike(@RequestParam("newsId") int newsId){
        return "sd";
        //在disLikeKey对应的集合中加入当前用户
//        long likeCount = likeService.disLike(hostHolder.getUser().getId(), EntityType.ENTITY_NEWS, newsId);
//        if(likeCount <= 0){
//            likeCount = 0;
//        }
//
//        //资讯上更新喜欢数
//        newsService.updateLikeCount(newsId, (int)likeCount);
//        return ToutiaoUtil.getJSONString(0, String.valueOf(likeCount));
    }
    @GetMapping("/getlikestatus")
    public int likestatus(@RequestParam("newsId") Integer newsId,@RequestParam("userId")Integer userId,@RequestParam("entityType")Integer entityType){
        int likeStatus = likeService.getLikeStatus(userId, entityType, newsId);
        return likeStatus;
    }
    @GetMapping("/getlikenum")
    public String getlikenum(@RequestParam("newsId") Integer newsId,@RequestParam("entityType")Integer entityType){
        long likeNumber = likeService.getLikeNumber(entityType, newsId);
        return String.valueOf(likeNumber);

    }
}
